package leetCode;

public class Q415 {
    public String addStrings(String num1, String num2) {
        int len1 = num1.length();
        int len2 = num2.length();
        int minLen = Math.min(len1,len2);
        int maxLen = Math.max(len1,len2);
        char[] res = new char[maxLen+1];

        //指针，1就是个位，2就是十位 nums[len-p]
        int buff = 0;
        int p = 1;
        for(; minLen-p >= 0 ;p++){
            int a = num1.charAt(len1 - p) - '0';
            int b = num2.charAt(len2 - p) - '0';
            buff = a+b+buff>9?1:0;
            res[res.length-p] = (char)('0'+(a+b+buff)%10);
        }

        String s = len1>=len2?num1:num2;
        for(int i = maxLen-minLen-1;i>=0;i--){
            int a = s.charAt(i) - '0';
            buff = a+buff>9?1:0;
            res[i] = (char)('0'+(a+buff)%10);
        }

        if(buff == 1){
            res[0] = '1';
            return String.valueOf(res);
        }

        return String.valueOf(res).substring(1);
    }

    public static void main(String[] args) {

//        System.out.println(new Q415().addStrings("11", "123"));
        Float f = Float.NaN;
        Float g = Float.NaN;
        System.out.println(f.equals(g));
    }
}
